package ai.peanut.selfbase.common.domain;

import ai.peanut.selfbase.common.constants.GlobalConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * shenghua.hu
 */
public class SystemManager {
	private static final Logger LOGGER = LoggerFactory.getLogger(SystemManager.class);

	public static volatile String sysName = null;
	private static volatile String sysCode = "0";
	public static boolean isInit = false;
	/**
	 * API调用签名secret
	 */
	public static String open_secret;

	public static String getSysName() {
		return sysName;
	}

	public static void setSysName(String sysName) {
		SystemManager.sysName = sysName;
	}

	public static String getSysCode() {
		if ("0".equals(sysCode)) {
			LOGGER.warn("[警告]没有设置系统码 application.properties ->'system.code'");
		}
		return sysCode;
	}

	public static void setSysCode(String sysCode) {
		SystemManager.sysCode = sysCode;
	}

	/**
	 * 将当前状态码追加系统码
	 * 
	 * @param code
	 * @return
	 */
	public static int appendSysCode(int code) {
		if (code < 0) {
			return -Integer.parseInt(sysCode + Math.abs(code));
		}
		return Integer.parseInt(sysCode + code);
	}

	/**
	 * 获取当前系统secret
	 * 
	 * @return
	 */
	public static String getOpenSecret() {
		if (open_secret == null) {
			LOGGER.info("没有获取到配置`{}`", GlobalConstant.OPEN_SECRET_CONFIG_KEY);
		}
		return open_secret;
	}

	public static Logger getLogger() {
		return LOGGER;
	}
}
